<!--
 * @Description:
 * @version:
 * @Author: 尹鹏孝
 * @Date: 2023-03-30 16:18:19
 * @LastEditors: 尹鹏孝
 * @LastEditTime: 2023-03-30 17:19:48
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>async函数</title>
</head>
<body>
    <script>

            let superagent = function (URL) {
                let xhr = new XMLHttpRequest();
                xhr.open("GET", URL)
                xhr.send();
                return xhr;

            }
            let MAX=3;
            let linkMore = async function () {
                let i;

                for (i = 0; i < MAX; ++i) {

                     try {
                        let result = await superagent('http://google.com/this-throws-an-error');
                        console.log(result)
                        break;
                    } catch (error) {
                        console.log(error)
                    }
                    console.log(i)
                }


                }

            linkMore(3)


            async function loginOrder(urls){

                const textPromises = urls.map(async url=>{
                    const response = await  await superagent(url);
                    return response.responseText;
                })
                 for (const textPromise of textPromises) {
                    console.log(await textPromise)
                }
            }
            loginOrder(['https://api.btstu.cn/sjbz/api.php', 'https://api.btstu.cn/sjbz/api.php', 'https://api.btstu.cn/sjbz/api.php', 'https://api.btstu.cn/sjbz/api.php'])

    </script>

</body>
</html>